package com.ruoyi.bom.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bom.domain.ErpOrderBom;
import com.ruoyi.bom.service.IErpOrderBomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单BOMController
 * 
 * @author ruoyi
 * @date 2025-07-23
 */
@RestController
@RequestMapping("/bom/bom")
public class ErpOrderBomController extends BaseController
{
    @Autowired
    private IErpOrderBomService erpOrderBomService;

    /**
     * 查询订单BOM列表
     */
    @PreAuthorize("@ss.hasPermi('bom:bom:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpOrderBom erpOrderBom)
    {
        startPage();
        List<ErpOrderBom> list = erpOrderBomService.selectErpOrderBomList(erpOrderBom);
        return getDataTable(list);
    }

    /**
     * 导出订单BOM列表
     */
    @PreAuthorize("@ss.hasPermi('bom:bom:export')")
    @Log(title = "订单BOM", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpOrderBom erpOrderBom)
    {
        List<ErpOrderBom> list = erpOrderBomService.selectErpOrderBomList(erpOrderBom);
        ExcelUtil<ErpOrderBom> util = new ExcelUtil<ErpOrderBom>(ErpOrderBom.class);
        util.exportExcel(response, list, "订单BOM数据");
    }

    /**
     * 获取订单BOM详细信息
     */
    @PreAuthorize("@ss.hasPermi('bom:bom:query')")
    @GetMapping(value = "/{salesOrderNumber}")
    public AjaxResult getInfo(@PathVariable("salesOrderNumber") String salesOrderNumber)
    {
        return success(erpOrderBomService.selectErpOrderBomBySalesOrderNumber(salesOrderNumber));
    }

    /**
     * 新增订单BOM
     */
    @PreAuthorize("@ss.hasPermi('bom:bom:add')")
    @Log(title = "订单BOM", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpOrderBom erpOrderBom)
    {
        return toAjax(erpOrderBomService.insertErpOrderBom(erpOrderBom));
    }

    /**
     * 修改订单BOM
     */
    @PreAuthorize("@ss.hasPermi('bom:bom:edit')")
    @Log(title = "订单BOM", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpOrderBom erpOrderBom)
    {
        return toAjax(erpOrderBomService.updateErpOrderBom(erpOrderBom));
    }

    /**
     * 删除订单BOM
     */
    @PreAuthorize("@ss.hasPermi('bom:bom:remove')")
    @Log(title = "订单BOM", businessType = BusinessType.DELETE)
	@DeleteMapping("/{salesOrderNumbers}")
    public AjaxResult remove(@PathVariable String[] salesOrderNumbers)
    {
        return toAjax(erpOrderBomService.deleteErpOrderBomBySalesOrderNumbers(salesOrderNumbers));
    }
}
